

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="nginx在工作中已经有好几个环境在使用了，每次都是重新去网上扒博客，各种编译配置，今天自己也整理一份安装文档和nginx.conf配置选项的说明，留作以后参考。像负载均衡配置（包括健康检查）、缓存（包括清空缓存）配置实例，请参考http://seanlook.com/2015/05/17/nginx-install-and-config ，ssl加密请参考 http://seanlook.com">
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="description" content="nginx在工作中已经有好几个环境在使用了，每次都是重新去网上扒博客，各种编译配置，今天自己也整理一份安装文档和nginx.conf配置选项的说明，留作以后参考。像负载均衡配置（包括健康检查）、缓存（包括清空缓存）配置实例，请参考http://seanlook.com/2015/05/17/nginx-install-and-config ，ssl加密请参考 http://seanlook.com">
<meta name="keywords" content="Nginx">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx 服务器安装及配置文件详解">
<meta property="og:url" content="https://kinzun.github.io/2017/05/04/NginxInstall-and-config/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:description" content="nginx在工作中已经有好几个环境在使用了，每次都是重新去网上扒博客，各种编译配置，今天自己也整理一份安装文档和nginx.conf配置选项的说明，留作以后参考。像负载均衡配置（包括健康检查）、缓存（包括清空缓存）配置实例，请参考http://seanlook.com/2015/05/17/nginx-install-and-config ，ssl加密请参考 http://seanlook.com">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-10-04T08:12:40.000Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Nginx 服务器安装及配置文件详解">
<meta name="twitter:description" content="nginx在工作中已经有好几个环境在使用了，每次都是重新去网上扒博客，各种编译配置，今天自己也整理一份安装文档和nginx.conf配置选项的说明，留作以后参考。像负载均衡配置（包括健康检查）、缓存（包括清空缓存）配置实例，请参考http://seanlook.com/2015/05/17/nginx-install-and-config ，ssl加密请参考 http://seanlook.com">
  
  <title>Nginx 服务器安装及配置文件详解 - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Nginx 服务器安装及配置文件详解">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2017-05-04 10:33" pubdate>
        2017年5月4日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      11k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      35 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Nginx 服务器安装及配置文件详解</h1>
            
            <div class="markdown-body">
              <p>nginx在工作中已经有好几个环境在使用了，每次都是重新去网上扒博客，各种编译配置，今天自己也整理一份安装文档和nginx.conf配置选项的说明，留作以后参考。像负载均衡配置（包括健康检查）、缓存（包括清空缓存）配置实例，请参考<a href="http://seanlook.com/2015/05/17/nginx-install-and-config" target="_blank" rel="noopener">http://seanlook.com/2015/05/17/nginx-install-and-config</a> ，ssl加密请参考 <a href="http://seanlook.com/2015/05/28/nginx-ssl/" target="_blank" rel="noopener">http://seanlook.com/2015/05/28/nginx-ssl/</a> 。</p>
<a id="more"></a>
<h3 id="1-安装nginx"><a href="#1-安装nginx" class="headerlink" title="1. 安装nginx"></a>1. 安装nginx</h3><h4 id="1-1-选择稳定版本"><a href="#1-1-选择稳定版本" class="headerlink" title="1.1 选择稳定版本"></a>1.1 选择稳定版本</h4><p>我们编译安装nginx来定制自己的模块，机器CentOS 6.2 x86_64。首先安装缺少的依赖包：</p>
<figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta">#</span><span class="bash"> yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel</span><br></code></pre></div></td></tr></table></figure>
<p>这些软件包如果yum上没有的话可以下载源码来编译安装，只是要注意编译时默认安装的目录，确保下面在安装nginx时能够找到这些动态库文件（ldconfig）。</p>
<p>从 <a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">http://nginx.org/en/download.html</a> 下载稳定版<code>nginx-1.6.3.tar.gz</code>到<code>/usr/local/src</code>下解压。</p>
<p>为了后续准备我们另外下载2个插件模块：<a href="https://github.com/yaoweibin/nginx_upstream_check_module/releases" target="_blank" rel="noopener">nginx_upstream_check_module-0.3.0.tar.gz</a> —— 检查后端服务器的状态，<a href="https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/downloads" target="_blank" rel="noopener">nginx-goodies-nginx-sticky-module-ng-bd312d586752.tar.gz</a>（建议在/usr/local/src下解压后将目录重命名为<code>nginx-sticky-module-ng-1.2.5</code>） —— 后端做负载均衡解决session sticky问题（与upstream_check模块结合使用需要另外打补丁，请参考<a href="http://seanlook.com/2015/06/02/nginx-cache-check/" target="_blank" rel="noopener">nginx负载均衡配置实战</a>）。</p>
<p>请注意插件与nginx的版本兼容问题，一般插件越新越好，nginx不用追新，稳定第一。nginx-1.4.7，nginx-sticky-module-1.1，nginx_upstream_check_module-0.2.0，这个搭配也没问题。sticky-1.1与nginx-1.6版本由于更新没跟上编译出错。（可以直接使用Tengine，默认就包括了这些模块）</p>
<figure class="highlight livescript"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined">[root@cachets nginx-<span class="hljs-number">1.6</span>.<span class="hljs-number">3</span>]<span class="hljs-comment"># pwd</span><br>/usr/local/src/nginx-<span class="hljs-number">1.6</span>.<span class="hljs-number">3</span><br>[root@cachets nginx-<span class="hljs-number">1.6</span>.<span class="hljs-number">3</span>]<span class="hljs-comment"># ./configure --prefix=/usr/local/nginx-1.6 --with-pcre \</span><br>&gt; --<span class="hljs-keyword">with</span>-http_stub_status_module --<span class="hljs-keyword">with</span>-http_ssl_module <span class="hljs-string">\</span><br>&gt; --<span class="hljs-keyword">with</span>-http_gzip_static_module --<span class="hljs-keyword">with</span>-http_realip_module <span class="hljs-string">\</span><br>&gt; --add-<span class="hljs-built_in">module</span>=../nginx_upstream_check_module-<span class="hljs-number">0.3</span>.<span class="hljs-number">0</span><br>[root@cachets nginx-<span class="hljs-number">1.6</span>.<span class="hljs-number">3</span>]<span class="hljs-comment"># make &amp;&amp; make install</span><br></code></pre></div></td></tr></table></figure>
<h4 id="1-2-常用编译选项说明"><a href="#1-2-常用编译选项说明" class="headerlink" title="1.2 常用编译选项说明"></a>1.2 常用编译选项说明</h4><p>nginx大部分常用模块，编译时./configure –help以–without开头的都默认安装。</p>
<ul>
<li>–prefix=PATH ： 指定nginx的安装目录。默认 /usr/local/nginx</li>
<li>–conf-path=PATH ： 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动，通过命令行中的-c选项。默认为prefix/conf/nginx.conf</li>
<li>–user=name： 设置nginx工作进程的用户。安装完成后，可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。–group=name类似</li>
<li>–with-pcre ： 设置PCRE库的源码路径，如果已通过yum方式安装，使用–with-pcre自动找到库文件。使用–with-pcre=PATH时，需要从PCRE网站下载pcre库的源码（版本4.4 – 8.30）并解压，剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。</li>
<li>–with-zlib=PATH ： 指定 zlib（版本1.1.3 – 1.2.5）的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。</li>
<li>–with-http_ssl_module ： 使用https协议模块。默认情况下，该模块没有被构建。前提是openssl与openssl-devel已安装</li>
<li>–with-http_stub_status_module ： 用来监控 Nginx 的当前状态</li>
<li>–with-http_realip_module ： 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For)，意义在于能够使得后台服务器记录原始客户端的IP地址</li>
<li>–add-module=PATH ： 添加第三方外部模块，如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译（Tengine可以在新加入module时无需重新编译）</li>
</ul>
<p>再提供一种编译方案：</p>
<figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined">./configure \<br><span class="hljs-meta">&gt;</span><span class="bash"> --prefix=/usr \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --sbin-path=/usr/sbin/nginx \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --conf-path=/etc/nginx/nginx.conf \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --error-log-path=/var/<span class="hljs-built_in">log</span>/nginx/error.log \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --http-log-path=/var/<span class="hljs-built_in">log</span>/nginx/access.log \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --pid-path=/var/run/nginx/nginx.pid  \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --lock-path=/var/lock/nginx.lock \   </span><br><span class="hljs-meta">&gt;</span><span class="bash"> --user=nginx \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --group=nginx \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --with-http_ssl_module \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --with-http_stub_status_module \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --with-http_gzip_static_module \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --http-client-body-temp-path=/var/tmp/nginx/client/ \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --with-pcre=../pcre-7.8</span><br><span class="hljs-meta">&gt;</span><span class="bash"> --with-zlib=../zlib-1.2.3</span><br></code></pre></div></td></tr></table></figure>
<h4 id="1-3-启动关闭nginx"><a href="#1-3-启动关闭nginx" class="headerlink" title="1.3 启动关闭nginx"></a>1.3 启动关闭nginx</h4><figure class="highlight shell"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-meta">#</span><span class="bash"><span class="hljs-comment"># 检查配置文件是否正确</span></span><br><span class="hljs-meta">#</span><span class="bash"> /usr/<span class="hljs-built_in">local</span>/nginx-1.6/sbin/nginx -t </span><br><span class="hljs-meta">#</span><span class="bash"> ./sbin/nginx -V     <span class="hljs-comment"># 可以看到编译选项</span></span><br><span class="hljs-meta">#</span><span class="bash"><span class="hljs-comment"># 启动、关闭</span></span><br><span class="hljs-meta">#</span><span class="bash"> ./sbin/nginx        <span class="hljs-comment"># 默认配置文件 conf/nginx.conf，-c 指定</span></span><br><span class="hljs-meta">#</span><span class="bash"> ./sbin/nginx -s stop</span><br>或 pkill nginx<br><span class="hljs-meta">#</span><span class="bash"><span class="hljs-comment"># 重启，不会改变启动时指定的配置文件</span></span><br><span class="hljs-meta">#</span><span class="bash"> ./sbin/nginx -s reload</span><br>或 kill -HUP `cat /usr/local/nginx-1.6/logs/nginx.pid`<br></code></pre></div></td></tr></table></figure>
<p>当然也可以将 nginx 作为系统服务管理，下载 nginx 到/etc/init.d/，修改里面的路径然后赋予可执行权限。</p>
<figure class="highlight coq"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"># service nginx &#123;start|<span class="hljs-type">stop</span>|<span class="hljs-type">status</span>|<span class="hljs-type">restart</span>|<span class="hljs-type">reload</span>|<span class="hljs-type">configtest</span>&#125;<br></code></pre></div></td></tr></table></figure>
<h4 id="1-4-yum安装"><a href="#1-4-yum安装" class="headerlink" title="1.4 yum安装"></a>1.4 yum安装</h4><p>—— 2015-05-22更新<br>yum安装rpm包会比编译安装简单很多，默认会安装许多模块，但缺点是如果你想以后安装第三方模块那就没办法了。</p>
<figure class="highlight ini"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-comment"># vi /etc/yum.repo.d/nginx.repo </span><br><span class="hljs-section">[nginx]</span> <br><span class="hljs-attr">name</span>=nginx repo <br><span class="hljs-attr">baseurl</span>=http://nginx.org/packages/centos/<span class="hljs-variable">$releasever</span>/<span class="hljs-variable">$basearch</span>/ <br><span class="hljs-attr">gpgcheck</span>=<span class="hljs-number">0</span> <br><span class="hljs-attr">enabled</span>=<span class="hljs-number">1</span><br></code></pre></div></td></tr></table></figure>
<p>剩下的就<code>yum install nginx</code>搞定，也可以<code>yum install nginx-1.6.3</code>安装指定版本（前提是你去packages里看到有对应的版本，默认是最新版稳定版）。</p>
<h3 id="2-nginx-conf配置文件"><a href="#2-nginx-conf配置文件" class="headerlink" title="2. nginx.conf配置文件"></a>2. nginx.conf配置文件</h3><p>Nginx配置文件主要分成四部分：main（全局设置）、server（主机设置）、upstream（上游服务器设置，主要为反向代理、负载均衡相关配置）和 location（URL匹配特定位置后的设置），每部分包含若干个指令。main部分设置的指令将影响其它所有部分的设置；server部分的指令主要用于指定虚拟主机域名、IP和端口；upstream的指令用于设置一系列的后端服务器，设置反向代理及后端服务器的负载均衡；location部分用于匹配网页位置（比如，根目录“/”,“/images”,等等）。他们之间的关系式：server继承main，location继承server；upstream既不会继承指令也不会被继承。它有自己的特殊指令，不需要在其他地方的应用。<br>当前nginx支持的几个指令上下文：</p>
<h4 id="2-1-通用"><a href="#2-1-通用" class="headerlink" title="2.1 通用"></a>2.1 通用</h4><p>下面的nginx.conf简单的实现nginx在前端做反向代理服务器的例子，处理js、png等静态文件，jsp等动态请求转发到其它服务器tomcat：</p>
<figure class="highlight nginx"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-attribute">user</span>  www www;<br><span class="hljs-attribute">worker_processes</span>  <span class="hljs-number">2</span>;<br><span class="hljs-attribute">error_log</span>  logs/error.log;<br><span class="hljs-comment">#error_log  logs/error.log  notice;</span><br><span class="hljs-comment">#error_log  logs/error.log  info;</span><br><span class="hljs-attribute">pid</span>        logs/nginx.pid;<br><span class="hljs-section">events</span> &#123;<br>    <span class="hljs-attribute">use</span> <span class="hljs-literal">epoll</span>;<br>    <span class="hljs-attribute">worker_connections</span>  <span class="hljs-number">2048</span>;<br>&#125;<br><span class="hljs-section">http</span> &#123;<br>    <span class="hljs-attribute">include</span>       mime.types;<br>    <span class="hljs-attribute">default_type</span>  application/octet-stream;<br>    <span class="hljs-comment">#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '</span><br>    <span class="hljs-comment">#                  '$status $body_bytes_sent "$http_referer" '</span><br>    <span class="hljs-comment">#                  '"$http_user_agent" "$http_x_forwarded_for"';</span><br>    <span class="hljs-comment">#access_log  logs/access.log  main;</span><br>    <span class="hljs-attribute">sendfile</span>        <span class="hljs-literal">on</span>;<br>    <span class="hljs-comment"># tcp_nopush     on;</span><br>    <span class="hljs-attribute">keepalive_timeout</span>  <span class="hljs-number">65</span>;<br>  <span class="hljs-comment"># gzip压缩功能设置</span><br>    <span class="hljs-attribute">gzip</span> <span class="hljs-literal">on</span>;<br>    <span class="hljs-attribute">gzip_min_length</span> <span class="hljs-number">1k</span>;<br>    <span class="hljs-attribute">gzip_buffers</span>    <span class="hljs-number">4</span> <span class="hljs-number">16k</span>;<br>    <span class="hljs-attribute">gzip_http_version</span> <span class="hljs-number">1</span>.<span class="hljs-number">0</span>;<br>    <span class="hljs-attribute">gzip_comp_level</span> <span class="hljs-number">6</span>;<br>    <span class="hljs-attribute">gzip_types</span> text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;<br>    <span class="hljs-attribute">gzip_vary</span> <span class="hljs-literal">on</span>;<br>  <br>  <span class="hljs-comment"># http_proxy 设置</span><br>    <span class="hljs-attribute">client_max_body_size</span>   <span class="hljs-number">10m</span>;<br>    <span class="hljs-attribute">client_body_buffer_size</span>   <span class="hljs-number">128k</span>;<br>    <span class="hljs-attribute">proxy_connect_timeout</span>   <span class="hljs-number">75</span>;<br>    <span class="hljs-attribute">proxy_send_timeout</span>   <span class="hljs-number">75</span>;<br>    <span class="hljs-attribute">proxy_read_timeout</span>   <span class="hljs-number">75</span>;<br>    <span class="hljs-attribute">proxy_buffer_size</span>   <span class="hljs-number">4k</span>;<br>    <span class="hljs-attribute">proxy_buffers</span>   <span class="hljs-number">4</span> <span class="hljs-number">32k</span>;<br>    <span class="hljs-attribute">proxy_busy_buffers_size</span>   <span class="hljs-number">64k</span>;<br>    <span class="hljs-attribute">proxy_temp_file_write_size</span>  <span class="hljs-number">64k</span>;<br>    <span class="hljs-attribute">proxy_temp_path</span>   /usr/local/nginx/proxy_temp <span class="hljs-number">1</span> <span class="hljs-number">2</span>;<br>  <span class="hljs-comment"># 设定负载均衡后台服务器列表 </span><br>    <span class="hljs-attribute">upstream</span>  backend  &#123; <br>              <span class="hljs-comment">#ip_hash; </span><br>              <span class="hljs-attribute">server</span>   <span class="hljs-number">192.168.10.100:8080</span> max_fails=<span class="hljs-number">2</span> fail_timeout=<span class="hljs-number">30s</span> ;  <br>              <span class="hljs-attribute">server</span>   <span class="hljs-number">192.168.10.101:8080</span> max_fails=<span class="hljs-number">2</span> fail_timeout=<span class="hljs-number">30s</span> ;  <br>    &#125;<br>  <span class="hljs-comment"># 很重要的虚拟主机配置</span><br>    <span class="hljs-section">server</span> &#123;<br>        <span class="hljs-attribute">listen</span>       <span class="hljs-number">80</span>;<br>        <span class="hljs-attribute">server_name</span>  itoatest.example.com;<br>        <span class="hljs-attribute">root</span>   /apps/oaapp;<br>        <span class="hljs-attribute">charset</span> utf-<span class="hljs-number">8</span>;<br>        <span class="hljs-attribute">access_log</span>  logs/host.access.log  main;<br>        <span class="hljs-comment">#对 / 所有做负载均衡+反向代理</span><br>        <span class="hljs-attribute">location</span> / &#123;<br>            <span class="hljs-attribute">root</span>   /apps/oaapp;<br>            <span class="hljs-attribute">index</span>  index.jsp index.html index.htm;<br>            <span class="hljs-attribute">proxy_pass</span>        http://backend;  <br>            <span class="hljs-attribute">proxy_redirect</span> <span class="hljs-literal">off</span>;<br>            <span class="hljs-comment"># 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP</span><br>            <span class="hljs-attribute">proxy_set_header</span>  Host  <span class="hljs-variable">$host</span>;<br>            <span class="hljs-attribute">proxy_set_header</span>  X-Real-IP  <span class="hljs-variable">$remote_addr</span>;  <br>            <span class="hljs-attribute">proxy_set_header</span>  X-Forwarded-For  <span class="hljs-variable">$proxy_add_x_forwarded_for</span>;<br>            <span class="hljs-attribute">proxy_next_upstream</span> <span class="hljs-literal">error</span> timeout invalid_header http_500 http_502 http_503 http_504;<br>            <br>        &#125;<br>        <span class="hljs-comment">#静态文件，nginx自己处理，不去backend请求tomcat</span><br>        <span class="hljs-attribute">location</span>  <span class="hljs-regexp">~* /download/</span> &#123;  <br>            <span class="hljs-attribute">root</span> /apps/oa/fs;  <br>            <br>        &#125;<br>        <span class="hljs-attribute">location</span> <span class="hljs-regexp">~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$</span>   <br>        &#123;   <br>            <span class="hljs-attribute">root</span> /apps/oaapp;   <br>            <span class="hljs-attribute">expires</span>      <span class="hljs-number">7d</span>; <br>        &#125;<br>       	<span class="hljs-attribute">location</span> /nginx_status &#123;<br>            <span class="hljs-attribute">stub_status</span> <span class="hljs-literal">on</span>;<br>            <span class="hljs-attribute">access_log</span> <span class="hljs-literal">off</span>;<br>            <span class="hljs-attribute">allow</span> <span class="hljs-number">192.168.10.0</span>/<span class="hljs-number">24</span>;<br>            <span class="hljs-attribute">deny</span> all;<br>        &#125;<br>        <span class="hljs-attribute">location</span> <span class="hljs-regexp">~ ^/(WEB-INF)/</span> &#123;   <br>            <span class="hljs-attribute">deny</span> all;   <br>        &#125;<br>        <span class="hljs-comment">#error_page  404              /404.html;</span><br>        <span class="hljs-comment"># redirect server error pages to the static page /50x.html</span><br>        <span class="hljs-comment">#</span><br>        <span class="hljs-attribute">error_page</span>   <span class="hljs-number">500</span> <span class="hljs-number">502</span> <span class="hljs-number">503</span> <span class="hljs-number">504</span>  /50x.html;<br>        <span class="hljs-attribute">location</span> = /50x.html &#123;<br>            <span class="hljs-attribute">root</span>   html;<br>        &#125;<br>    &#125;<br>  <span class="hljs-comment">## 其它虚拟主机，server 指令开始</span><br>&#125;<br></code></pre></div></td></tr></table></figure>
<h3 id="2-2-常用指令说明"><a href="#2-2-常用指令说明" class="headerlink" title="2.2 常用指令说明"></a>2.2 常用指令说明</h3><h4 id="2-2-1-main全局配置"><a href="#2-2-1-main全局配置" class="headerlink" title="2.2.1 main全局配置"></a>2.2.1 main全局配置</h4><p>nginx在运行时与具体业务功能（比如http服务或者email服务代理）无关的一些参数，比如工作进程数，运行的身份等。</p>
<ul>
<li><code>woker_processes 2</code><br>在配置文件的顶级<em>main</em>部分，worker角色的工作进程的个数，master进程是接收并分配请求给worker处理。这个数值简单一点可以设置为cpu的核数<code>grep ^processor /proc/cpuinfo | wc -l</code>，也是 auto 值，如果开启了ssl和gzip更应该设置成与逻辑CPU数量一样甚至为2倍，可以减少I/O操作。如果nginx服务器还有其它服务，可以考虑适当减少。</li>
<li><code>worker_cpu_affinity</code><br>也是写在<em>main</em>部分。在高并发情况下，通过设置cpu粘性来降低由于多CPU核切换造成的寄存器等现场重建带来的性能损耗。如<code>worker_cpu_affinity 0001 0010 0100 1000;</code> （四核）。</li>
<li><code>worker_connections 2048</code><br>写在<em>events</em>部分。每一个worker进程能并发处理（发起）的最大连接数（包含与客户端或后端被代理服务器间等所有连接数）。nginx作为反向代理服务器，计算公式 <code>最大连接数 = worker_processes * worker_connections/4</code>，所以这里客户端最大连接数是1024，这个可以增到到8192都没关系，看情况而定，但不能超过后面的<code>worker_rlimit_nofile</code>。当nginx作为http服务器时，计算公式里面是除以2。</li>
<li><code>worker_rlimit_nofile 10240</code><br>写在<em>main</em>部分。默认是没有设置，可以限制为操作系统最大的限制65535。</li>
<li><code>use epoll</code><br>写在<code>events</code>部分。在Linux操作系统下，nginx默认使用epoll事件模型，得益于此，nginx在Linux操作系统下效率相当高。同时Nginx在OpenBSD或FreeBSD操作系统上采用类似于epoll的高效事件模型kqueue。在操作系统不支持这些高效模型时才使用select。</li>
</ul>
<h4 id="2-2-2-http服务器"><a href="#2-2-2-http服务器" class="headerlink" title="2.2.2 http服务器"></a>2.2.2 http服务器</h4><p>与提供http服务相关的一些配置参数。例如：是否使用keepalive啊，是否使用gzip进行压缩等。</p>
<ul>
<li><code>sendfile on</code><br>开启高效文件传输模式，sendfile指令指定nginx是否调用sendfile函数来输出文件，减少用户空间到内核空间的上下文切换。对于普通应用设为 on，如果用来进行下载等应用磁盘IO重负载应用，可设置为off，以平衡磁盘与网络I/O处理速度，降低系统的负载。</li>
<li><code>keepalive_timeout 65</code> : 长连接超时时间，单位是秒，这个参数很敏感，涉及浏览器的种类、后端服务器的超时设置、操作系统的设置，可以另外起一片文章了。长连接请求大量小文件的时候，可以减少重建连接的开销，但假如有大文件上传，65s内没上传完成会导致失败。如果设置时间过长，用户又多，长时间保持连接会占用大量资源。</li>
<li><code>send_timeout</code> : 用于指定响应客户端的超时时间。这个超时仅限于两个连接活动之间的时间，如果超过这个时间，客户端没有任何活动，Nginx将会关闭连接。</li>
<li><code>client_max_body_size 10m</code><br>允许客户端请求的最大单文件字节数。如果有上传较大文件，请设置它的限制值</li>
<li><code>client_body_buffer_size 128k</code><br>缓冲区代理缓冲用户端请求的最大字节数</li>
</ul>
<p><strong>模块http_proxy：</strong><br>这个模块实现的是nginx作为反向代理服务器的功能，包括缓存功能（另见<a href="http://seanlook.com/2015/06/02/nginx-cache-check/" target="_blank" rel="noopener">文章</a>）</p>
<ul>
<li><code>proxy_connect_timeout 60</code><br>nginx跟后端服务器连接超时时间(代理连接超时)</li>
<li><code>proxy_read_timeout 60</code><br>连接成功后，与后端服务器两个成功的响应操作之间超时时间(代理接收超时)</li>
<li><code>proxy_buffer_size 4k</code><br>设置代理服务器（nginx）从后端realserver读取并保存用户<strong>头</strong>信息的缓冲区大小，默认与proxy_buffers大小相同，其实可以将这个指令值设的小一点</li>
<li><code>proxy_buffers 4 32k</code><br>proxy_buffers缓冲区，nginx针对单个连接缓存来自后端realserver的<strong>响应</strong>，网页平均在32k以下的话，这样设置</li>
<li><code>proxy_busy_buffers_size 64k</code><br>高负荷下缓冲大小（proxy_buffers*2）</li>
<li><code>proxy_max_temp_file_size</code><br>当 proxy_buffers 放不下后端服务器的响应内容时，会将一部分保存到硬盘的临时文件中，这个值用来设置最大临时文件大小，默认1024M，它与 proxy_cache 没有关系。大于这个值，将从upstream服务器传回。设置为0禁用。</li>
<li><code>proxy_temp_file_write_size 64k</code><br>当缓存被代理的服务器响应到临时文件时，这个选项限制每次写临时文件的大小。<code>proxy_temp_path</code>（可以在编译的时候）指定写到哪那个目录。</li>
</ul>
<p>proxy_pass，proxy_redirect见 location 部分。</p>
<p>模块http_gzip：</p>
<ul>
<li>gzip on : 开启gzip压缩输出，减少网络传输。</li>
<li>gzip_min_length 1k ： 设置允许压缩的页面最小字节数，页面字节数从header头得content-length中进行获取。默认值是20。建议设置成大于1k的字节数，小于1k可能会越压越大。</li>
<li>gzip_buffers 4 16k ： 设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。4 16k代表以16k为单位，安装原始数据大小以16k为单位的4倍申请内存。</li>
<li>gzip_http_version 1.0 ： 用于识别 http 协议的版本，早期的浏览器不支持 Gzip 压缩，用户就会看到乱码，所以为了支持前期版本加上了这个选项，如果你用了 Nginx 的反向代理并期望也启用 Gzip 压缩的话，由于末端通信是 http/1.0，故请设置为 1.0。</li>
<li>gzip_comp_level 6 ： gzip压缩比，1压缩比最小处理速度最快，9压缩比最大但处理速度最慢(传输快但比较消耗cpu)</li>
<li>gzip_types ：匹配mime类型进行压缩，无论是否指定,”text/html”类型总是会被压缩的。</li>
<li>gzip_proxied any ： Nginx作为反向代理的时候启用，决定开启或者关闭后端服务器返回的结果是否压缩，匹配的前提是后端服务器必须要返回包含”Via”的 header头。</li>
<li>gzip_vary on ： 和http头有关系，会在响应头加个 Vary: Accept-Encoding ，可以让前端的缓存服务器缓存经过gzip压缩的页面，例如，用Squid缓存经过Nginx压缩的数据。</li>
</ul>
<h4 id="2-2-3-server虚拟主机"><a href="#2-2-3-server虚拟主机" class="headerlink" title="2.2.3 server虚拟主机"></a>2.2.3 server虚拟主机</h4><p>http服务上支持若干虚拟主机。每个虚拟主机一个对应的server配置项，配置项里面包含该虚拟主机相关的配置。在提供mail服务的代理时，也可以建立若干server。每个server通过监听地址或端口来区分。</p>
<ul>
<li><code>listen</code><br>监听端口，默认80，小于1024的要以root启动。可以为<code>listen *:80</code>、<code>listen 127.0.0.1:80</code>等形式。</li>
<li><code>server_name</code><br>服务器名，如<code>localhost</code>、<code>www.example.com</code>，可以通过正则匹配。</li>
</ul>
<p><strong>模块http_stream</strong><br>这个模块通过一个简单的调度算法来实现客户端IP到后端服务器的负载均衡，<code>upstream</code>后接负载均衡器的名字，后端realserver以 <code>host:port options;</code> 方式组织在 {} 中。如果后端被代理的只有一台，也可以直接写在 proxy_pass 。</p>
<h4 id="2-2-4-location"><a href="#2-2-4-location" class="headerlink" title="2.2.4 location"></a>2.2.4 location</h4><p>http服务中，某些特定的URL对应的一系列配置项。</p>
<ul>
<li><code>root /var/www/html</code><br>定义服务器的默认网站根目录位置。如果<code>location</code>URL匹配的是子目录或文件，<code>root</code>没什么作用，一般放在<code>server</code>指令里面或<code>/</code>下。</li>
<li><code>index index.jsp index.html index.htm</code><br>定义路径下默认访问的文件名，一般跟着<code>root</code>放</li>
<li><code>proxy_pass http:/backend</code><br>请求转向backend定义的服务器列表，即反向代理，对应<code>upstream</code>负载均衡器。也可以<code>proxy_pass http://ip:port</code>。</li>
<li><code>proxy_redirect off;</code><br><code>proxy_set_header Host $host;</code><br><code>proxy_set_header X-Real-IP $remote_addr;</code><br><code>proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</code><br>这四个暂且这样设，如果深究的话，每一个都涉及到很复杂的内容，也将通过另一篇文章来解读。</li>
</ul>
<p>关于location匹配规则的写法，可以说尤为关键且基础的，参考文章 <a href="http://seanlook.com/2015/05/17/nginx-location-rewrite/" target="_blank" rel="noopener">nginx配置location总结及rewrite规则写法</a>;</p>
<h4 id="2-3-其它"><a href="#2-3-其它" class="headerlink" title="2.3 其它"></a>2.3 其它</h4><h4 id="2-3-1-访问控制-allow-deny"><a href="#2-3-1-访问控制-allow-deny" class="headerlink" title="2.3.1 访问控制 allow/deny"></a>2.3.1 访问控制 allow/deny</h4><p>Nginx 的访问控制模块默认就会安装，而且写法也非常简单，可以分别有多个allow,deny，允许或禁止某个ip或ip段访问，依次满足任何一个规则就停止往下匹配。如：</p>
<figure class="highlight nginx"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-attribute">location</span> /nginx-status &#123;<br>  <span class="hljs-attribute">stub_status</span> <span class="hljs-literal">on</span>;<br>  <span class="hljs-attribute">access_log</span> <span class="hljs-literal">off</span>;<br><span class="hljs-comment">#  auth_basic   "NginxStatus";</span><br><span class="hljs-comment">#  auth_basic_user_file   /usr/local/nginx-1.6/htpasswd;</span><br>  <span class="hljs-attribute">allow</span> <span class="hljs-number">192.168.10.100</span>;<br>  <span class="hljs-attribute">allow</span> <span class="hljs-number">172.29.73.0</span>/<span class="hljs-number">24</span>;<br>  <span class="hljs-attribute">deny</span> all;<br>&#125;<br></code></pre></div></td></tr></table></figure>
<p>我们也常用 httpd-devel 工具的 htpasswd 来为访问的路径设置登录密码：</p>
<figure class="highlight routeros"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-comment"># htpasswd -c htpasswd admin</span><br>New passwd:<br>Re-type new password:<br>Adding password <span class="hljs-keyword">for</span><span class="hljs-built_in"> user </span>admin<br><span class="hljs-comment"># htpasswd htpasswd admin    //修改admin密码</span><br><span class="hljs-comment"># htpasswd htpasswd sean    //多添加一个认证用户</span><br></code></pre></div></td></tr></table></figure>
<p>这样就生成了默认使用CRYPT加密的密码文件。打开上面nginx-status的两行注释，重启nginx生效。</p>
<h4 id="2-3-2-列出目录-autoindex"><a href="#2-3-2-列出目录-autoindex" class="headerlink" title="2.3.2 列出目录 autoindex"></a>2.3.2 列出目录 autoindex</h4><p>Nginx默认是不允许列出整个目录的。如需此功能，打开nginx.conf文件，在location，server 或 http段中加入<code>autoindex on;</code>，另外两个参数最好也加上去:</p>
<ul>
<li><code>autoindex_exact_size off;</code> 默认为on，显示出文件的确切大小，单位是bytes。改为off后，显示出文件的大概大小，单位是kB或者MB或者GB</li>
<li><code>autoindex_localtime on;</code><br>默认为off，显示的文件时间为GMT时间。改为on后，显示的文件时间为文件的服务器时间</li>
</ul>
<figure class="highlight nginx"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs undefined"><span class="hljs-attribute">location</span> /images &#123;<br>  <span class="hljs-attribute">root</span>   /var/www/nginx-default/images;<br>  <span class="hljs-attribute">autoindex</span> <span class="hljs-literal">on</span>;<br>  <span class="hljs-attribute">autoindex_exact_size</span> <span class="hljs-literal">off</span>;<br>  <span class="hljs-attribute">autoindex_localtime</span> <span class="hljs-literal">on</span>;<br>  &#125;<br></code></pre></div></td></tr></table></figure>
<p><strong>参考</strong></p>
<ul>
<li><a href="http://liuqunying.blog.51cto.com/3984207/1420556" target="_blank" rel="noopener">http://liuqunying.blog.51cto.com/3984207/1420556</a></li>
<li><a href="http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity" target="_blank" rel="noopener">http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity</a></li>
<li><a href="http://wiki.nginx.org/HttpCoreModule#sendfile" target="_blank" rel="noopener">http://wiki.nginx.org/HttpCoreModule#sendfile</a></li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Nginx/">Nginx</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2017/05/05/nginx-config-summary/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Nginx 配置文件总结</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2017/03/07/NetworkManager-command-line-tool/">
                        <span class="hidden-mobile">NetworkManager command line tool</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
